#include "stdafx.h"
#include "Game.h"
#include "Libraries\Time.h"
#include "InputManager\InputManager.h"
#include "SoundManager\SoundManager.h"
#include "Game States\StateManager.h"
#include "Renderer\Renderer.h"

Game::Game()
{
	hWnd = NULL;
	windowWidth = 0;
	windowHeight = 0;
	isWindowed = 0;

	time = nullptr;
	inputManager = nullptr;
	soundManager = nullptr;
	stateManager = nullptr;
}

Game::~Game()
{
}

void Game::Initialize(HWND hWnd, unsigned short windowWidth, unsigned short windowHeight, bool isWindowed)
{
	this->hWnd = hWnd;
	this->windowWidth = windowWidth;
	this->windowHeight = windowHeight;
	this->isWindowed = isWindowed;

	time = new Time;
	inputManager = new InputManager;
	soundManager = new SoundManager;
	stateManager = new StateManager;
	renderer = new Renderer;

	time->Initialize();
	soundManager->Initialize();
	stateManager->Initialize(this);
	renderer->InitD3D(hWnd, windowWidth, windowHeight);
}

bool Game::GameLoop(void)
{
	if (!stateManager->Input())
		return false;
	stateManager->Update(time->GetElapsedTime());

	time->Update();
	soundManager->Update();
	inputManager->Update();
	renderer->RenderFrame();

	return true;
}

void Game::Shutdown(void)
{
	SafeDelete(time);
	SafeDelete(inputManager);
	soundManager->Shutdown();
	stateManager->Shutdown();
	SafeDelete(stateManager);
	renderer->CleanD3D();
}